<?php

function smarty_function_videoplayer($aParams)
{
	if ( !isset($aParams['url']) )
	{
		return;
	}

	$sFileExt = substr($aParams['url'], -3);
	$sFileExt4 = substr($aParams['url'], -4);

	if ( $sFileExt == 'flv' )
	{
		$sVariables = (App::getParam('ffmpeg_watermark') ? "&logo=". App::getParam('ffmpeg_waterimage', "", App::getParam('url') . "file/pic/watermark/video.gif") ."" : '');
		$sVariables .= "&autostart=". (App::getParam('vp_autostart') ? 'true' : 'false') ."";
		$sVariables .= "&repeat=". (App::getParam('vp_repeat') ? 'true' : 'false') ."";
		$sVariables .= "&backcolor=". App::getParam('vp_backcolor') ."";
		$sVariables .= "&frontcolor=". App::getParam('vp_frontcolor') ."";
		$sVariables .= "&lightcolor=". App::getParam('vp_lightcolor') ."";
		$sVariables .= "&link=". App::makeUrl('public.videos') ."";
		$sVariables .= "&allowfullscreen=true";

		$aParams['url'] = str_replace(App::getParam('video.url'), '', $aParams['url']);
		$sPlayer = '<script type="text/javascript">EmbedVideo("file/player/'. (substr($aParams['url'], 0, 7) == 'http://' ? 'http' : '') .'flvplayer.swf?file='. $aParams['url'] .''. $sVariables .'", "'. $aParams['width'] .'", "'. $aParams['height'] .'");</script>
		<noscript><div style="font-weight:bold; text-align:center; padding:10px;">'. App::format('Mod_Site.warning_no_javascript') .'</div></noscript>
		';
  	}
	elseif ( $sFileExt == 'mov' )
	{
		$sPlayer = "<script type=\"text/javascript\" src=\"design/js/quicktime.js\"></script>
	    <script type=\"text/javascript\"> QT_WriteOBJECT_XHTML('". $aParams['url'] ."', '". $aParams['width'] ."', '". $aParams['height'] ."', '', 'controller', 'true', 'autoplay', 'true'); </script>";
  	}
  	elseif ( $sFileExt == 'wmv' || $sFileExt == 'asf' || $sFileExt == 'asx' || $sFileExt == 'wvx' || $sFileExt == 'mpg' || $sFileExt == 'avi' || $sFileExt4 == 'mpeq' )
	{
		$sPlayer = "
		<object id='mediaPlayer' width=\"". $aParams['width'] ."\" height=\"". $aParams['height'] ."\" classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95'codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701'standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject'>
		<param name='fileName' value=\"". $aParams['url'] ."\">
		<param name='animationatStart' value='false'>
		<param name='transparentatStart' value='true'>
		<param name='autoStart' value=\"true\">
		<param Name='autoSize' Value=\"false\">
		<param name='showControls' value=\"true\">
		<param name='loop' value=\"false\">
		<param name='showstatusbar' value=\"true\">
		<embed type='application/x-mplayer2' pluginspage='http://microsoft.com/windows/mediaplayer/en/download/' id='mediaPlayer' displaysize='4' autosize='-1' bgcolor='darkblue' showcontrols=\"true\" showtracker='-1' showdisplay='0' showstatusbar='-1' videoborder3d='-1' width=\"". $aParams['width'] ."\" height=\"". $aParams['height'] ."\" src=\"". $aParams['url'] ."\" autostart=\"true\" designtimesp='5311' loop=\"false\" filename=\"". $aParams['url'] ."\" animationatstart=\"false\" transparentatstart=\"true\">
		</embed>
		</object>
		";
  	}
  	
else
  	{
		$sPlayer = '<script type="text/javascript">EmbedVideo("'. $aParams['url'] .'", "'. $aParams['width'] .'", "'. $aParams['height'] .'");</script>
		<noscript><div style="font-weight:bold; text-align:center; padding:10px;">'. App::format('Mod_Site.warning_no_javascript') .'</div></noscript>
		';
	}

	return $sPlayer;
}

?>